//
//  UIBarButtonItem+CustomItem.swift
//  weiBoOfSwift
//
//  Created by simon on 15/12/5.
//  Copyright © 2015年 simon. All rights reserved.
//

import UIKit

let KnavigationFontSize:CGFloat = 14

extension UIBarButtonItem{

    class func customItem(title title:String? = nil ,imgName:String? = nil ,target: AnyObject?, action: Selector)->(UIBarButtonItem) {
       
        let customBtn = UIButton()
        
        customBtn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        if let t = title{
            customBtn.titleLabel?.font = UIFont.systemFontOfSize(KnavigationFontSize)
            customBtn.setTitle(t, forState:.Normal)
            
            customBtn.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
            
            customBtn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        }
        
        if let img = imgName {
            
        customBtn.setImage(UIImage(named: "\(img)_highlighted"), forState: .Highlighted)
            
        customBtn.setImage(UIImage(named: img), forState:.Normal)
        }
        
        customBtn.sizeToFit()

        
     return  UIBarButtonItem(customView: customBtn)
    }
}